import {CHANGE_TAB} from '../actions/actionType.js'
import {TABKEY} from '../config.js'

const initiState = {
  tabs: [
    {
      name: '首页',
      key: TABKEY.home
    },
    {
      name: '订单',
      key: TABKEY.order
    },
    {
      name: '我的',
      key: TABKEY.my
    }
  ],
  activeKey: TABKEY.my
}

export const changeTab = (state, action) => {
  let activeKey = action.obj.activeKey

  return {...state, activeKey}
}

const tabReducer = (state = initiState, action) => {
  switch(action.type){
    case CHANGE_TAB:
      return changeTab(state, action)
    default:
      return state
  }
}

export default tabReducer